package com.wsjc.manager.service.rpc.data.utils;

import java.io.FileWriter;
import java.io.IOException;
import java.util.List;


public class CreateTableSql {

	
	/**
	 * 创建push表水平分表sql
	 */
	public static void createPushTableSql(List<String> news){
		FileWriter writer = null;
		try {
			writer = new FileWriter("D:/wj_push.txt");
			for(String str : news ){
				
				StringBuffer buf = new StringBuffer();
		        buf.append("DROP TABLE IF EXISTS 'public'.'wj_push_"+str+"';" + "\r\n");
		        buf.append("CREATE TABLE 'public'.'wj_push_"+str+"' (" + "\r\n");
		        buf.append("'id' int8 NOT NULL," + "\r\n");
		        buf.append("'title' varchar(15) COLLATE 'default'," + "\r\n");
		        buf.append("'content' varchar(255) COLLATE 'default'," + "\r\n");
		        buf.append("'scope'varchar(6) COLLATE 'default'," + "\r\n");
		        buf.append("'type' varchar(8) COLLATE 'default'," + "\r\n");
		        buf.append("'is_read' varchar(2) COLLATE 'default'," + "\r\n");
		        buf.append("'detection_time' timestamp(6)," + "\r\n");
		        buf.append("'recorder_id' varchar(35) COLLATE 'default'" + "\r\n");
		        buf.append(")" + "\r\n");
		        buf.append("WITH (OIDS=FALSE);" + "\r\n");
		        
	            writer.write(buf.toString());
	            writer.flush();
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}finally {
			try {
				writer.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	
	
	/**
	 * 创建灭菌表水平分表sql
	 */
	public static void createSterilizationTableSql(List<String> news){
		FileWriter writer = null;
		try {
			writer = new FileWriter("D:/wj_sterilization.txt");
			for(String str : news ){
				
				StringBuffer buf = new StringBuffer();
		        buf.append("DROP TABLE IF EXISTS 'public'.'wj_sterilization_"+str+"';" + "\r\n");
		        buf.append("CREATE TABLE 'public'.'wj_sterilization_"+str+"' (" + "\r\n");
		        buf.append("'id' varchar(50) COLLATE 'default' NOT NULL," + "\r\n");
		        buf.append("'hospital_name' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'hospital_id' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'device_number' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'op_department' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'op_persion' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'judged' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'oss_dir' varchar(35) COLLATE 'default'," + "\r\n");
		        
		        buf.append("'device_program_number' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'device_set_cool' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'device_set_time' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'keep_time' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'cool_max_value' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'pressure_vacuum_degree' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'pressure_range' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'pressure_reverse_cool' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'device_keeptime' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'cool_volatility' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'data_package_name' varchar(35) COLLATE 'default'," + "\r\n");
		        		
		        		
		        buf.append("'package_info' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'camera_index' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'upload_unit' varchar(30) COLLATE 'default'," + "\r\n");
		        buf.append("'detection_result' varchar(20) COLLATE 'default'," + "\r\n");
		        buf.append("'device_kinds' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'device_brand' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'device_capacity' varchar(40) COLLATE 'default'," + "\r\n");
		        buf.append("'recorder_id' varchar(35) COLLATE 'default'," + "\r\n");
		        buf.append("'reason_style' varchar(150) COLLATE 'default'," + "\r\n");

		        
		        buf.append("'reason_explain' varchar(50) COLLATE 'default'," + "\r\n");
		        buf.append("'device_level' varchar(10) COLLATE 'default'," + "\r\n");
		        buf.append("'device_type' varchar(30) COLLATE 'default'," + "\r\n");
		        buf.append("'dispose_explain' varchar(100) COLLATE 'default'," + "\r\n");
		        buf.append("'dispose_style' varchar(20) COLLATE 'default'," + "\r\n");
		        
		        buf.append("'detection_time' timestamp(6)," + "\r\n");
		        buf.append("'create_time' timestamp(6)," + "\r\n");
		        buf.append("'edit_time' timestamp(6)," + "\r\n");
		        buf.append("'version' int8" + "\r\n");
		        buf.append(")" + "\r\n");
		        buf.append("WITH (OIDS=FALSE);" + "\r\n");
		        
		       /* DROP TABLE IF EXISTS "public"."wj_sterilization";
		        CREATE TABLE "public"."wj_sterilization" (
		        "id" varchar(50) COLLATE "default" NOT NULL,
		        "hospital_id" varchar(40) COLLATE "default",
		        "device_number" varchar(35) COLLATE "default",
		        "op_department" varchar(35) COLLATE "default",
		        "op_persion" varchar(35) COLLATE "default",
		        "judged" varchar(35) COLLATE "default",
		        
		        "device_program_number" varchar(35) COLLATE "default",
		        "device_set_cool" varchar(35) COLLATE "default",
		        "device_set_time" varchar(40) COLLATE "default",
		        "keep_time" varchar(35) COLLATE "default",
		        "cool_max_value" varchar(40) COLLATE "default",
		        "pressure_vacuum_degree" varchar(35) COLLATE "default",
		        "pressure_range" varchar(35) COLLATE "default",
		        
		        "pressure_reverse_cool" varchar(35) COLLATE "default",
		        "device_keeptime" varchar(35) COLLATE "default",
		        "cool_volatility" varchar(35) COLLATE "default",
		        "data_package_name" varchar(35) COLLATE "default",
		        
		        
		        "package_info" varchar(35) COLLATE "default",
		        "camera_index" varchar(35) COLLATE "default",
		        "upload_unit" varchar(30) COLLATE "default",
		        "detection_result" varchar(20) COLLATE "default",
		        "device_kinds" varchar(40) COLLATE "default",
		        "device_brand" varchar(40) COLLATE "default",
		        "device_capacity" varchar(40) COLLATE "default",
		        "detection_time" timestamp(6),
		        
		        "recorder_id" varchar(35) COLLATE "default",
		        "reason_style" varchar(150) COLLATE "default",
		        "reason_explain" varchar(50) COLLATE "default",
		        "device_level" varchar(10) COLLATE "default",
		        "device_type" varchar(30) COLLATE "default",
		        "create_time" timestamp(6),
		        "dispose_explain" varchar(100) COLLATE "default",
		        "dispose_style" varchar(20) COLLATE "default",
		        "edit_time" timestamp(6),
		        "version" int8
		        )*/
		        
	            writer.write(buf.toString());
	            writer.flush();
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}finally {
			try {
				writer.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	
	
}
